package com.education.schedule.dynamic;

import com.education.domain.SpringScheduledCron;

/**
 * Created by zhangjiawen on 2019/10/30.
 */
public interface ScheduledOfTask extends Runnable {
    /**
     * 定时任务方法
     */
    void execute();
    /**
     * 实现控制定时任务启用或禁用的功能
     */

    @Override
    default void run() {
        SpringScheduledCronRepository repository = SpringUtils.getBean(SpringScheduledCronRepository.class);
        SpringScheduledCron scheduledCron = repository.findByCronKey(this.getClass().getName());
        if ("0".equals(scheduledCron.getStatus())) {
            return;
        }
        execute();
    }
}